/**
 * @param {number} n
 * @return {number}
 */
 var countNumbersWithUniqueDigits = function(n) {
  let fact = (start, step) => {
      if(step === 0) return 1;
      let r = 1;
      while(step > 0) {
          r *= start;
          start--;
          step--;
      }
      return r;
  }
  let ret = 1;
  let cache = [1]
  for(let i = 1; i <= n; i++) {
      ret += 9 * fact(9, i - 1);
      cache.push(ret);
  }
  console.log(cache);
  return ret;
};

/**
 * @param {number} n
 * @return {number}
 */
 var countNumbersWithUniqueDigits = function(n) {
  return [
      1,     10,
     91,    739,
   5275,  32491,
 168571, 712891,
2345851
][n];
};